;
export class Play {
	/**
	 * 1.wss://xxx/xxx.flv  流畅
	 * 2.https://xxx/xxx.flv
	 */
	//
	wssPlayer;
	boxDom;
	done = false;

	/**
	 * .mute(); 静音   cancelMute()
	 * pause(); 停止
	 * destroy();销毁 
	 * play();播放
	 * setVolume(v) 音量
	 * setRotate(v ) 角度
	 * setScaleMode(v)
	 * setFullscreen(true/false) 全屏
	 * clearView() 清屏
	 * startRecord('webm')
	 * stopRecordAndSave
	 * screenshot 截图
	 * setBufferTime(Number(v))
	 */
	constructor({
		dom,
		back
	}) {
		// rotate: 270,
		// isResize: false,
		// videoBuffer: 0.2, // 缓存时长
		// isResize: false,
		// text: "",
		// loadingText: "",
		// useMSE: false,
		// debug: true,
		console.log("dom", dom);
		let showOperateBtns = true;
		let player = new window.Jessibuca({
			container: dom,
			decoder: "/jssibuca/decoder.js",
			rotate: 0,
			isResize: false,
			loadingText: "正在解析",
			isFlv: true,
			debug: true,

			showBandwidth: showOperateBtns, // 显示网速
			operateBtns: {
				fullscreen: showOperateBtns,
				screenshot: showOperateBtns,
				play: showOperateBtns,
				audio: showOperateBtns,
			},
			forceNoOffscreen: true,
			isNotMute: false,
		});
		this.boxDom = dom;

		if (player.hasLoaded()) {
			this.done = true;
			back?.();
			//console.log("初始化完成");
			// player.play("http://flv.bdplay.nodemedia.cn/live/bbb.flv");
		} else {
			player.on('load', () => {
				this.done = true;
				back?.();
				//	console.log("初始化完成");
				//player.play("http://flv.bdplay.nodemedia.cn/live/bbb.flv");
			});
		}
		this.wssPlayer = player;
	}
	purl;
	_h = -1;
	hPlay(url) {
		clearTimeout(this._h)
		if (this.done) {
			console.log("play", url);
			//this.hStop();	
			this.wssPlayer.pause();
			this.wssPlayer.play(url).then(() => {
				console.log("播放成功");
			}).catch((e) => {
				console.log('play error', e)
			});
		} else {
			this.purl = url;
			this._h = setTimeout(() => {
				this.hPlay(url);
			}, 10);
		}
	}

	hStop() {
		this.wssPlayer.destroy();
		this.onStop();
	};
	onStop() {}
}